﻿@using System.Collections;
@using Entidades.Sistema.Base;
@{

    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();
    
    List<Empleado> empleados = (List<Empleado>)ViewBag.Empleado;
    empleados = empleados.Where(x => x.Productos.Any(y => y.IdProducto == (int)ViewData["IdProduccionProducto"])).ToList();
    
    var grid =  Html.DevExpress().GridView(
        settings => {
            settings.Name = "detail" + ViewData["IdProduccionProducto"];
            settings.KeyFieldName = "IdProduccionProductoDetalle";
            settings.CallbackRouteValues = new { Controller = "DiagramacionProduccion", Action = "EditProduccionProductosDetallePartial", IdProduccionProducto = ViewData["IdProduccionProducto"] };
            settings.SettingsEditing.BatchUpdateRouteValues = new { Controller = "DiagramacionProduccion", Action = "EditProduccionProductosDetalleUpdatePartial", IdProduccionProducto = ViewData["IdProduccionProducto"] };
            settings.SettingsEditing.Mode = GridViewEditingMode.Batch;
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
            
            
            
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowNewButtonInHeader = true;
            settings.CommandColumn.ShowDeleteButton = true;

            settings.Columns.Add(
               column =>
               {
                   //porque no existe en el combo box el empleado.
                   column.FieldName = "Empleado.IdEmpleado";
                   column.Caption = "Empleado";
                   column.ColumnType = MVCxGridViewColumnType.ComboBox;
                   var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                   comboBoxProperties.DataSource = empleados;
                   comboBoxProperties.TextField = "NombreApellido";
                   comboBoxProperties.ValueField = "IdEmpleado";
                   comboBoxProperties.ValueType = typeof(int);
                   comboBoxProperties.IncrementalFilteringMode = IncrementalFilteringMode.StartsWith;
                   comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;

               });          
            
            
            settings.Columns.Add(
               column =>
               {
                   column.FieldName = "CantidadProducir";
                   column.Caption = "Cantidad a Producir";
                   column.ColumnType = MVCxGridViewColumnType.SpinEdit;
                   var spinEditProperties = column.PropertiesEdit as SpinEditProperties;
               });

            settings.Settings.ShowFooter = true;
            settings.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "CantidadProducir");

            
            if (ViewData["EditError"] != null)
            {
                settings.Settings.ShowFooter = true;
                settings.SetFooterRowTemplateContent(c =>
                {
                    Html.ViewContext.Writer.Write("<b style='color: Red'>" + (string)ViewData["EditError"] + "</b>");
                });
            }
        });

    if (ViewData["EditError"] != null)
    {
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()
    




